package io.renren.modules.generator.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.generator.entity.OrderDetailEntity;
import io.renren.modules.generator.service.OrderDetailService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-12-12 09:53:09
 */
@RestController
@RequestMapping("generator/orderdetail")
public class OrderDetailController {
    @Autowired
    private OrderDetailService orderDetailService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:orderdetail:list")
    public R list(@RequestParam Map<String, Object> params){

        Query query = new Query(params);

        List<OrderDetailEntity> list = orderDetailService.queryPage(query);

        int total =orderDetailService.queryPageTotal(params);

        PageUtils pageUtils = new PageUtils(list, total, query.getLimit(), query.getCurrPage());

        return R.ok().put("page", pageUtils);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:orderdetail:info")
    public R info(@PathVariable("id") Integer id){
			OrderDetailEntity orderDetail = orderDetailService.selectById(id);

        return R.ok().put("orderDetail", orderDetail);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:orderdetail:save")
    public R save(@RequestBody OrderDetailEntity orderDetail){
			orderDetailService.insert(orderDetail);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:orderdetail:update")
    public R update(@RequestBody OrderDetailEntity orderDetail){
			orderDetailService.updateById(orderDetail);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:orderdetail:delete")
    public R delete(@RequestBody Integer[] ids){
			orderDetailService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

    @GetMapping("/queryDetailByOrderId")
    public R queryDetailByOrderId(@RequestParam int orderId){

        List<OrderDetailEntity> orderDetailEntities= orderDetailService.queryDetailByOrderId(orderId);
        return R.ok().put("data",orderDetailEntities);
    }

}
